import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'ProductAnalysisM',
  state: {},
  effects: {
    // 获取产品下的所有组合
    *getProductGroup({ payload, callback }, { call, put }) {
      const res = yield call(api.getProductGroup, payload);
      if (res && res.success) {
        callback(res.data);
      } else {
        callback();
        message.error(res?.errorMsg || '未知错误');
      }
    },

    //现金流明细（表格）
    *cashFlowDetails({ payload, callback }, { call, put, select }) {
      const res = yield call(api.forecast.cashFlowDetails, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg || '查询现金流明细失败!');
      }
    },

    //获取汇总信息
    *getAccount({ payload, callback }, { call, put }) {
      const res = yield call(api.forecast.getAccount, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error('查询总计信息失败');
      }
    },
  },

  reducers: {
    setState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
